package com.fgsort;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.swing.JOptionPane;
 
import jxl.*;
import jxl.read.biff.BiffException;

public class ExcelReadSymbolFile {

	public List<String> ReadSymbolFile(String sExcelFile) {

		///symbol file array to return to calling method 
		List<String> lstSymbolFile = new ArrayList<String>();
		
		try {
			
			File exlFile = new File(sExcelFile);
			WorkbookSettings ws = new WorkbookSettings();
			ws.setLocale(new Locale("en", "EN"));
			Workbook workbook = Workbook.getWorkbook(exlFile, ws);

			Sheet sheet = workbook.getSheet(0);
			//System.out.println(sheet.getRows());
			for (int row = 0; row < sheet.getRows(); row++) {
				try {
					Cell cell = sheet.getCell(0, row);	
					lstSymbolFile.add(cell.getContents());	///symbol name
				} catch (ArrayIndexOutOfBoundsException e)	{
					lstSymbolFile.add("");
				}
			 
				try {
					Cell cell = sheet.getCell(1, row);	
					lstSymbolFile.add(cell.getContents());	///io number
				} catch (ArrayIndexOutOfBoundsException e)	{
					lstSymbolFile.add("");
				}
				
				try {
					Cell cell = sheet.getCell(2, row);	
					lstSymbolFile.add(cell.getContents());	///type
				} catch (ArrayIndexOutOfBoundsException e)	{
					lstSymbolFile.add("");
				}

				try {
					Cell cell = sheet.getCell(3, row);	
					lstSymbolFile.add(cell.getContents());	///comment
				} catch (ArrayIndexOutOfBoundsException e)	{
					lstSymbolFile.add("");
				}
			
			}
				
			///close workbook
			workbook.close();

			
		} catch (IOException e) {
			//e.printStackTrace();
			JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"The excel file: " + sExcelFile + " cannot be read or does not exist",
					"Information",JOptionPane.ERROR_MESSAGE);
			
		} catch (BiffException e) {
			JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"The excel file: " + sExcelFile + " cannot be read or does not exist",
					"Information",JOptionPane.ERROR_MESSAGE);			
			//e.printStackTrace();
		}
			///symbol file contents
			return lstSymbolFile;

	}

	
	
}

